package com.zds.hj.poseidon.biz.dispatcher.credit.demo;

import com.zds.boot.common.exception.BusinessException;
import com.zds.boot.dispatch.annotation.DispatcherHandler;
import com.zds.boot.dispatch.comm.enums.ModuleNodeTypeEnum;
import com.zds.boot.dispatch.dto.BaseReqModel;
import com.zds.boot.dispatch.dto.BaseResultModel;
import com.zds.hj.poseidon.biz.dispatcher.credit.CreditCheckAbsHandler;
import com.zds.hj.poseidon.facade.dto.hpp.credit.CreditInfoEntityDto;
import com.zds.hj.product.facade.constant.ApplicationContainerConstant;
import com.zds.zly.common.enums.HjResultCodeEnum;
import com.zds.zly.common.utils.EmptyChecker;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author duanhao
 * @Description 个人信息收集
 * @Date 2023/6/6 9:39
 */
@DispatcherHandler(value = "PersonalInfoCollectHandler", desc = "个人信息收集", applicationContainer = ApplicationContainerConstant.FRONT_END, nodeType = ModuleNodeTypeEnum.BUSINESS)
@Slf4j
public class PersonalInfoCollectHandler extends CreditCheckAbsHandler {


    @Override
    public void creditDoExecute(BaseReqModel params, BaseResultModel resultModel, CreditInfoEntityDto reqData, CreditInfoEntityDto dbData) {
        log.info("个人信息收集入参: {}", reqData);
        if (EmptyChecker.isEmpty(reqData.getName())) {
            throw new BusinessException("姓名不能为空", HjResultCodeEnum.NO_DATA_FOUND.code());
        }
        dbData.setName(reqData.getName());
        dbData.setAddress(reqData.getAddress());
        dbData.setPhone(reqData.getPhone());
        dbData.setCardNo(reqData.getCardNo());
    }

    @Override
    public Object paramsFerry(Object o) {
        CreditInfoEntityDto dbDto = (CreditInfoEntityDto) o;
        CreditInfoEntityDto creditInfoEntityDto = new CreditInfoEntityDto();
        creditInfoEntityDto.setName(dbDto.getName());
        creditInfoEntityDto.setCardNo(dbDto.getCardNo());
        creditInfoEntityDto.setPhone(dbDto.getPhone());
        creditInfoEntityDto.setAddress(dbDto.getAddress());
        return creditInfoEntityDto;
    }
}
